<?php
/**
 * +----------------------------------------------------------------------
 * | 用户中心控制器
 * +----------------------------------------------------------------------
 *                      .::::.
 *                    .::::::::.            | AUTHOR: siyu
 *                    :::::::::::           | EMAIL: 407593529@qq.com
 *                 ..:::::::::::'           | QQ: 407593529
 *             '::::::::::::'               | DATETIME: 2019/07/19
 *                .::::::::::
 *           '::::::::::::::..
 *                ..::::::::::::.
 *              ``::::::::::::::::
 *               ::::``:::::::::'        .:::.
 *              ::::'   ':::::'       .::::::::.
 *            .::::'      ::::     .:::::::'::::.
 *           .:::'       :::::  .:::::::::' ':::::.
 *          .::'        :::::.:::::::::'      ':::::.
 *         .::'         ::::::::::::::'         ``::::.
 *     ...:::           ::::::::::::'              ``::.
 *   ```` ':.          ':::::::::'                  ::::..
 *                      '.:::::'                    ':'````..
 * +----------------------------------------------------------------------
 */

namespace app\api\controller;


use app\api\service\JwtAuth;
use app\common\model\Cate;
use app\common\model\Debris;
use app\common\model\Page;
use app\common\model\System;
use app\common\model\Users;
use app\common\model\Article;
use think\facade\Db;
use think\facade\Request;

class Index extends Base
{
    /**
     * 控制器中间件 [登录、注册 不需要鉴权]
     * @var array
     */
    protected $middleware = [
        'app\api\middleware\Api' => ['except' => ['index', 'recyclingclass', 'config', 'about', 'adlist','policy']],
    ];

    public function index()
    {
        $articleList = Article::where('cate_id', 6)->where('status', 1)->order('sort')->order('id', 'desc')->limit(5)->select();
        return $this->result($articleList, 0, 1, '');
    }

    public function recyclingClass()
    {
        $cateList = Cate::where('parent_id', 15)->order('sort')->column('cate_name,id,ico_image,image');
        return $this->result($cateList, 0, 1, '');
    }

    public function config()
    {
        $config = System::where('id', 1)->column('icp,url,address,contacts,tel,mobile_phone,email,qq,qrcode,title,mobile');
        return $this->result($config[0], 0, 1, '');

    }

    public function about()
    {
        $about = Page::where('id', 1)->column('content');
        return $this->result($about, 0, 1, '');
    }

    public function adList()
    {
        $ad = Db::name('ad')->where('status', 1)->order('sort')->select();
        return $this->result($ad, 0, 1, '');
    }

    public function policy()
    {
        $params = $this->request->param();

        $debris = Db::name('debris')->where('name', $params['type'])->find();
        if ($debris) {
            return $this->result($debris, 0, 1, '');
        }
        return $this->result('', 1, 0, '');
    }

}
